package com.example.medicine.Mapper;

import com.example.medicine.Bean.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface fjglMapper {
//    @Select("select * from [jingfang]")
//    List<jingfang> getAll();
    @Select("SELECT jingfang.*,yh.company\n" +
            "            FROM jingfang\n" +
            "            left join(\n" +
            "            select userid,company \n" +
            "            from yonghu\n" +
            "            where userid in (select createuser from jingfang)) as yh \n" +
            "            on jingfang.createuser=yh.userid;")
    List<jingfangWithCompany> getAll();
    @Select("select * from [jingfang_peifang] where jingfang=#{jingfang}")
    List<jingfang_peifang> getAll2(int jingfang);

    @Select("select * from [jingfang] where id=#{id}")
    jingfang getById1(int id);


    @Insert("insert into [jingfang](jingfangming ,laiyuan,leixing,jixing,fanglun,fangjimingyi,chaodai,liupai,gongneng,zhuzhi,zhuzhizhengzhuang,yongfayongliang,jinji,jinguzhi,createuser,createtime) " +
            "values(#{jingfangming},#{laiyuan},#{leixing},#{jixing},#{fanglun},#{fangjimingyi},#{chaodai},#{liupai},#{gongneng},#{zhuzhi},#{zhuzhizhengzhuang},#{yongfayongliang},#{jinji},#{jinguzhi},#{createuser},getdate()) ")
    void insert1(jingfang jingfang);

    @Insert("insert into [jingfang_peifang](jingfang,yaowu,yongliang,cankaoyongliang,sort) values(#{jingfang},#{yaowu},#{yongliang},#{cankaoyongliang},#{sort})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert2(jingfang_peifang jingfang_peifang);

    /**
     * 批量插入
     * @param jingfang
     */
    @Insert("<script>INSERT INTO [jingfang] (jingfangming ,laiyuan,leixing,jixing,fanglun,yongfayongliang,jinguzhi,fangjimingyi,chaodai,liupai,gongneng,zhuzhi,zhuzhizhengzhuang,jinji,createuser,createtime) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.jingfangming},#{item.laiyuan},#{item.leixing},#{item.jixing},#{item.fanglun},#{item.yongfayongliang},#{item.jinguzhi},#{item.fangjimingyi},#{item.chaodai},#{item.liupai},#{item.gongneng},#{item.zhuzhi},#{item.zhuzhizhengzhuang},#{item.jinji},#{item.createuser},getdate())" +
            "</foreach></script>")
    void batchInsertjingfang(@Param("list") List<jingfang> jingfang);
    @Update("update [jingfang] set jingfangming=#{jingfangming},laiyuan=#{laiyuan},leixing=#{leixing},jixing=#{jixing},fanglun=#{fanglun},fangjimingyi=#{fangjimingyi},chaodai=#{chaodai}," +
            "liupai=#{liupai},gongneng=#{gongneng},zhuzhi=#{zhuzhi},zhuzhizhengzhuang=#{zhuzhizhengzhuang},yongfayongliang=#{yongfayongliang},jinji=#{jinji},jinguzhi=#{jinguzhi},shenhe=#{shenhe},shr=#{shr},shsj=getdate() where id=#{id} ")
    void  update1(jingfang jingfang);

    @Update("update [jingfang_peifang] set jingfang=#{jingfang},yaowu=#{yaowu},yongliang=#{yongliang},cankaoyongliang=#{cankaoyongliang} where id=#{id} ")
    void  update2(jingfang_peifang jingfang_peifang);
    @Update("update [jingfang_peifang] set sort=#{sort} where id=#{id} ")
    void  update3(jingfang_peifang jingfang_peifang);
    @Update("update [jingfang] set shenhe=#{shenhe},shr=#{shr},shsj=GETDATE() where id=#{id}")
    void updateShenhe(jingfang jingfang);

    @Delete("delete from [jingfang] where id=#{id}")
    void deleteById1(int id);

    @Delete("delete from [jingfang_peifang] where id=#{id}")
    void deleteById2(int id);
}
